import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../tools_base/loading/l_error_widget.dart';
import '../../../tools_base/loading/loading_center_widget.dart';
import '../../../tools_base/refresh/pull_refresh.dart';
import 'mine_follow_sub_logic.dart';

enum FollowType {
  user,
  topic,
  actress;
}

class MineFollowSubPage extends StatelessWidget {
  final FollowType pageType; //  0 博主， 1 粉丝， 2 话题
  final int? uid;

  MineFollowSubPage({super.key, required this.pageType, this.uid});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GetBuilder<MineFollowSubLogic>(
          global: false,
          init: instanceController(pageType, uid: uid),
          builder: (logic) {
            return pullYsRefresh(
                onRefresh: (refreshController) => logic.fetchPageData(),
                onLoading: (refreshController) => logic.fetchPageData(isRefresh: false),
                onInit: (ctr) => logic.refreshController = ctr,
                child: () {
                  if (logic.isLoading) return const LoadingCenterWidget();
                  if (logic.dataSource.isEmpty)
                    return CErrorWidget(
                      retryOnTap: () {
                        logic.fetchPageData();
                      },
                    );
                  if (logic.isGridStyle)
                    return GridView.builder(
                      padding: EdgeInsets.only(left: 16, right: 16, top: 12),
                      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2,
                        mainAxisSpacing: 10,
                        crossAxisSpacing: 5,
                        childAspectRatio: 165 / 143,
                      ),
                      itemCount: logic.dataSource.length,
                      itemBuilder: (BuildContext context, int index) {
                        return logic.instanceChildItem(index);
                      },
                    );
                  return ListView.builder(
                    padding: EdgeInsets.only(top: 12),
                    itemCount: logic.dataSource.length,
                    itemBuilder: (BuildContext context, int index) {
                      return logic.instanceChildItem(index);
                    },
                  );
                }());
          }),
    );
  }
}
